using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class TemplateProperties : BasePage
{
    public override Acms.Bll.Role.Roles[] AllowedRoles
    {
        get { return new Acms.Bll.Role.Roles[] { Acms.Bll.Role.Roles.Developer }; }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                TemplateId = int.Parse(Request.QueryString["Id"]);
            }
            catch
            {
            }
            if (Template == null || template.SiteId != AcmsSite.Id)
            {
                pnlFound.Visible = false;
                pnlNotFound.Visible = true;
                TemplateId = 0;
            }
            else
            {
                pnlNotFound.Visible = false;
                pnlFound.Visible = true;
                DataBind();
            }
        }
    }

    private int TemplateId
    {
        get 
        {
            if (ViewState["TemplateId"] is int)
            {
                return (int)ViewState["TemplateId"];
            }
            else
            {
                return 0;
            }
        }
        set 
        {
            ViewState["TemplateId"] = value;
        }
    }

    private Acms.Bll.Template template;
    protected Acms.Bll.Template Template
    {
        get
        {
            if (template == null && TemplateId > 0)
            {
                template = Acms.Bll.Template.GetById(TemplateId);
            }
            return template;
        }
    }

    public override void DataBind()
    {
        if (Template != null)
        {
            litName.Text = Template.Name;
        }
    }
    protected void dsTemplateProperties_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.TemplateControl> e)
    {
        e.SetData(Acms.Bll.TemplateControl.GetAllByTemplateId(Template.Id));
    }
    protected void dsTemplateProperties_UpdatingData(object sender, Acms.DataControls.UpdatingDataEventArgs<Acms.Bll.TemplateControl> e)
    {
        if (e.Action == Acms.DataControls.UpdateAction.Insert)
        {
            e.Item.TemplateId = Template.Id;
        }
    }

    protected void dsPropertyType_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.ControlType> e)
    {
        e.SetData(Acms.Bll.ControlType.GetAllBySiteId(AcmsSite.Id));
    }
}
